from enum import Enum
from typing import List


class UserRole(str, Enum):
    """用户角色枚举"""
    ADMIN = "admin"           # 系统管理员
    MANAGER = "manager"       # 运维经理
    TECHNICIAN = "technician" # 技术员
    USER = "user"            # 普通用户


class DeviceStatus(str, Enum):
    """设备状态枚举"""
    ONLINE = "online"         # 在线
    OFFLINE = "offline"       # 离线
    FAULT = "fault"          # 故障
    MAINTENANCE = "maintenance" # 维护中


class DeviceType(str, Enum):
    """设备类型枚举"""
    PORTABLE_TOILET = "portable_toilet"  # 便携式厕所
    DISPENSER = "dispenser"              # 分发器
    CLEANER = "cleaner"                  # 清洁器


class WorkOrderStatus(str, Enum):
    """工单状态枚举"""
    PENDING = "pending"         # 待处理
    ASSIGNED = "assigned"       # 已分配
    IN_PROGRESS = "in_progress" # 进行中
    ON_HOLD = "on_hold"        # 暂停
    COMPLETED = "completed"     # 已完成
    CANCELLED = "cancelled"     # 已取消


class WorkOrderPriority(str, Enum):
    """工单优先级枚举"""
    LOW = "low"         # 低
    MEDIUM = "medium"   # 中
    HIGH = "high"       # 高
    URGENT = "urgent"   # 紧急


class WorkOrderType(str, Enum):
    """工单类型枚举"""
    MAINTENANCE = "maintenance" # 维护
    REPAIR = "repair"          # 修理
    INSPECTION = "inspection"   # 检查
    INSTALLATION = "installation" # 安装
    CLEANING = "cleaning"      # 清洁


class AlertLevel(str, Enum):
    """告警级别枚举"""
    INFO = "info"         # 信息
    WARNING = "warning"   # 警告
    ERROR = "error"       # 错误
    CRITICAL = "critical" # 严重


class AlertType(str, Enum):
    """告警类型枚举"""
    FAULT = "fault"                    # 故障告警
    LOW_MATERIALS = "low_materials"    # 耗材不足
    OFFLINE = "offline"                # 设备离线
    MAINTENANCE_DUE = "maintenance_due" # 维护到期
    HIGH_USAGE = "high_usage"          # 使用量过高
    TEMPERATURE_HIGH = "temperature_high" # 温度过高
    HUMIDITY_HIGH = "humidity_high"    # 湿度过高
    BATTERY_LOW = "battery_low"        # 电池电量低


class NotificationType(str, Enum):
    """通知类型枚举"""
    EMAIL = "email"       # 邮件通知
    SMS = "sms"          # 短信通知
    PUSH = "push"        # 推送通知
    WEBHOOK = "webhook"   # Webhook通知


class SensorType(str, Enum):
    """传感器类型枚举"""
    DOOR_SENSOR = "door_sensor"         # 门锁状态传感器
    WATER_LEVEL = "water_level"         # 水箱液位传感器
    WASTE_LEVEL = "waste_level"         # 污物箱液位传感器
    PAPER_LEVEL = "paper_level"         # 纸巾余量传感器
    SOAP_LEVEL = "soap_level"           # 洗手液余量传感器
    TEMPERATURE = "temperature"         # 温度传感器
    HUMIDITY = "humidity"               # 湿度传感器
    OCCUPANCY = "occupancy"             # 人体感应传感器
    BATTERY_LEVEL = "battery_level"     # 电池电量传感器


class ControlCommandType(str, Enum):
    """控制指令类型枚举"""
    DOOR_CONTROL = "door_control"       # 门锁控制
    LIGHT_CONTROL = "light_control"     # 照明控制
    VENTILATION_CONTROL = "ventilation_control" # 通风控制
    WATER_PUMP_CONTROL = "water_pump_control"   # 水泵控制
    ALARM_CONTROL = "alarm_control"     # 报警控制
    MAINTENANCE_MODE = "maintenance_mode" # 维护模式


class PermissionAction(str, Enum):
    """权限动作枚举"""
    CREATE = "create"   # 创建
    READ = "read"       # 读取
    UPDATE = "update"   # 更新
    DELETE = "delete"   # 删除
    ASSIGN = "assign"   # 分配
    EXECUTE = "execute" # 执行


class LocationZone(str, Enum):
    """位置区域枚举"""
    ZONE_A = "zone_a"   # A区
    ZONE_B = "zone_b"   # B区
    ZONE_C = "zone_c"   # C区
    ZONE_D = "zone_d"   # D区
    ZONE_E = "zone_e"   # E区


# 角色权限映射
ROLE_PERMISSIONS = {
    UserRole.ADMIN: [
        PermissionAction.CREATE,
        PermissionAction.READ,
        PermissionAction.UPDATE,
        PermissionAction.DELETE,
        PermissionAction.ASSIGN,
        PermissionAction.EXECUTE
    ],
    UserRole.MANAGER: [
        PermissionAction.READ,
        PermissionAction.UPDATE,
        PermissionAction.ASSIGN,
        PermissionAction.EXECUTE
    ],
    UserRole.TECHNICIAN: [
        PermissionAction.READ,
        PermissionAction.UPDATE,
        PermissionAction.EXECUTE
    ],
    UserRole.USER: [
        PermissionAction.READ
    ]
}

# 告警级别颜色映射
ALERT_LEVEL_COLORS = {
    AlertLevel.INFO: "#1890ff",      # 蓝色
    AlertLevel.WARNING: "#faad14",   # 橙色
    AlertLevel.ERROR: "#f5222d",     # 红色
    AlertLevel.CRITICAL: "#722ed1"   # 紫色
}

# 设备状态颜色映射
DEVICE_STATUS_COLORS = {
    DeviceStatus.ONLINE: "#52c41a",     # 绿色
    DeviceStatus.OFFLINE: "#d9d9d9",    # 灰色
    DeviceStatus.FAULT: "#f5222d",      # 红色
    DeviceStatus.MAINTENANCE: "#faad14" # 橙色
}

# 工单优先级颜色映射
WORK_ORDER_PRIORITY_COLORS = {
    WorkOrderPriority.LOW: "#52c41a",     # 绿色
    WorkOrderPriority.MEDIUM: "#1890ff", # 蓝色
    WorkOrderPriority.HIGH: "#faad14",   # 橙色
    WorkOrderPriority.URGENT: "#f5222d"  # 红色
}